package com.example.democlient.network.clientpackets;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import com.example.democlient.TaskListActivity;
import com.example.democlient.model.Task;
import com.example.democlient.network.packet.ClientPacket;

public class CM_TASK_QUERY_RESPONSE extends ClientPacket {

    private int response;
    private static final Class<? extends Activity> calssz = TaskListActivity.class;
    public CM_TASK_QUERY_RESPONSE(int opcode) {
        super(opcode);
    }

    @Override
    protected void readImpl() {
    	this.response = readC();
    }

    @Override
    protected void runImpl() {
        switch (response) {
        	case 1:
        		List<Task> list = new ArrayList<Task>();
        		while(getRemainingBytes()!=0){
        			Task task = new Task();
        			task.setAddressId(readD());
        			task.setAddressStr(readS());
        			task.setTelephone(readS());
        			task.setRemark(readS());
        			task.setCreateDate(readS());
        			task.setFlag(readC());
        			task.setXaxis(readDF());
        			task.setYaxis(readDF());
        			task.setId(readD());
        			task.setAreaName(readS());
        			task.setPauseFlag((byte)readC());
        			task.setFinishFlag((byte)readC());
        			list.add(task);
        		}
        		super.getApp().taskList=list;
        	default:
        		super.getApp().getHander(calssz).sendEmptyMessage(response);
                break;
        }
    }
}
